package com.ly.demo.lamdastream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author liuyang
 * @des
 * @Version 1.0
 * @Date: 28/06/2021 17:50
 */
public class EnumStreamExample {
    public static void main(String[] args) throws InterruptedException {
        DaysOfWeekEnum.stream().filter(d -> d.getTypeOfDay().equals("off"))
            .forEach(d -> System.out.println(d.getTypeOfDay()));

        Stream<DaysOfWeekEnum> a = DaysOfWeekEnum.stream().filter(d -> d.getTypeOfDay().equals("off"));
        System.out.println(a);

        List<DaysOfWeekEnum> list =
            DaysOfWeekEnum.stream().filter(d -> d.getTypeOfDay().equals("off")).collect(Collectors.toList());

        for (DaysOfWeekEnum e : list) {
            System.out.println(e.getTypeOfDay());
        }

        System.err.println(DaysOfWeekEnum.getDaysOfWeekEnum(6));
        System.err.println(DaysOfWeekEnum.getDaysOfWeekEnum(7));

        System.out.println(IntStream.range(0, 100).parallel().findAny());
        System.out.println(IntStream.range(0, 100).parallel().findAny());
        System.out.println(IntStream.range(0, 100).parallel().findAny());
        System.out.println(IntStream.range(0, 100).parallel().findAny());

        List<String> lst1 =
            Arrays.asList("Jhonny", "David", "Jack", "Duke", "Jill", "Dany", "Julia", "Jenish", "Divya");
        List<String> lst2 =
            Arrays.asList("Jhonny", "David", "Jack", "Duke", "Jill", "Dany", "Julia", "Jenish", "Divya");

        Optional<String> findFirst = lst1.parallelStream().filter(s -> s.startsWith("D")).findFirst();
        Optional<String> fidnAny = lst2.parallelStream().filter(s -> s.startsWith("J")).findAny();
        Optional<String> findFirstJ = lst2.parallelStream().filter(s -> s.startsWith("J")).findFirst();
        System.out.println(findFirst.get());
        System.out.println(findFirstJ.get());
        //会随机地打印出Jhonny/Jack/Jill/Julia
        System.out.println(fidnAny.get());

    }
}
